<?php

namespace XiaoZhuBundle\Controller;

use AdminsBundle\Entity\Page;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use XiaoZhuBundle\Entity\UserBasic;
use XiaoZhuBundle\Helper\MyController;
/**
 * @Route("/page")
 */
class PageController extends MyController
{
    /**
     * @Route("/{id}", name="showPage")
     */
    public function showPage(Page $page)
    {
        $info["classes"] = $this->getAllPage();
        $info["page"] = $page;
        return $this->render('@XiaoZhu/page.html.twig', $info);
    }

    public function getAllPage()
    {
        $rep = $this->DB("AdminsBundle:Page");
        $pages = $rep->findAll();
        $data = array();
        foreach ($pages as $page) {
            $key = $page->getOrders() * 10000000 + $page->getId();
            $data[$key] = array(
                "id"    => $page->getId(),
                "name"  => $page->getTitle(),
            );
        }
        ksort($data);
        return $data;
    }
}
